{extend name="public/base"/}
{block name="body"}
<link href="/static/css/common.css" type="text/css" rel="stylesheet">
<link href="/static/css/index.css" type="text/css" rel="stylesheet">
<style type="text/css">
	input{border:solid 1px #ddd;height:31px;font-size:14px;padding-left:4px;}
	.formbox1{margin:5px 0;}
	.smname{margin:2px 0;}
	.select-boxs{display:inline-block;}
</style>
<title>编辑产品</title>
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add">
		<input type="hidden" class="input-text" value="{$data.id}" id="id" name="id">
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">分类选择</label>
			<div class="formControls col-xs-8 col-sm-9">
				<span class="select-boxs" style="width:150px;">
					<select name="cates" id="cates" class="select">
					  {foreach $cates as $key=>$vo}
					  	<option value="{$vo.id}" {if $vo.id==$data.c_id}selected{/if}>&nbsp;{$vo.catename}&nbsp;</option>
					  {/foreach}
					</select>
				</span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">标题：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$data.title}" placeholder="标题" id="title" name="title">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">图片：</label>
			<div class="formControls col-xs-8 col-sm-9">
                <div style="position:relative;" id="drop_area"></div>
                <p style="color:#ccc;font-size:12px;">建议尺寸宽高:240*200</p>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">图片组：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="img-box full">
					<section class=" img-section">
						<p class="up-p">作品图片：<span class="up-span">最多可以上传9张图片，马上上传</span></p>
						<div class="z_photo upimg-div clear">
								{if $data.imgs}
							{volist name="data['imgsarr']" id="value" key="kk"}
							<section class="up-section fl">
								<span class="up-span"></span>
								<img class="close-upimg" src="/static/img/a7.png">
								<img class="up-img" src="{$value}">
								<p class="img-name-p"><input type="hidden" name="imgsarr{$kk}" value="{$kk}"></p>
								<input id="taglocation" name="taglocation" value="" type="hidden"><input id="tags" name="tags" value="" type="hidden">
							</section>
							{/volist}
								{/if}
							<section class="z_file fl" style="{if $data.imgs&&count($data.imgsarr)>=9}display:none;{/if}">
								<img src="/static/img/a11.png" class="add-img">
								<input type="file" name="file" id="file" class="file" value="" accept="image/jpg,image/jpeg,image/png,image/bmp" multiple="">
							</section>
						</div>
					</section>
				</div>
		        <aside class="mask works-mask">
					<div class="mask-content">
						<p class="del-p">您确定要删除作品图片吗？</p>
						<p class="check-p"><span class="del-com wsdel-ok">确定</span><span class="wsdel-no">取消</span></p>
					</div>
				</aside>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">商品推荐：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea rows="6" style="width:100%" name="recommendation">{$data.recommendation}</textarea>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">商品详情：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<script id="editor" name="detail" type="text/plain" style="width:100%;height:400px;">{:htmlspecialchars_decode($data.detail)}</script>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">排序：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="number" class="input-text" value="{$data.sort}" placeholder="0" id="sort" name="sort">
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">规格：</label>
			<div class="formControls col-xs-8 col-sm-9">
                <div>
                      <p>1.添加更改规格及规格项后请点击下方的【刷新规格项目表】来更新数据。</p>
                      <p>2. 每一种规格代表不同型号，例如颜色为一种规格，尺寸为一种规格，如果设置多规格，手机用户必须每一种规格都选择一个规格项，才能添加购物车或购买。</p>
                      <p>3.最多只能添加三个规格</p>
                </div>

                <div>
                	<div class="control-group">
	                    <div class="btn btn-primary" id="add_lv1">
	                        <span class="fa fa-plus"></span>添加一个规格
	                    </div>
	                    <div class="btn btn-success" id="update_table">
	                        <span class="fa fa-refresh"></span>刷新规格项目表
	                    </div>
	                </div>
                    <div id="lv_table_con" class="control-group" style="display: none;">
                          <div class="controls">
                              <div id="lv_table">
                                  
                              </div>
                          </div>
                    </div>
                    <div>
                       
                    </div>
                </div>
            </div>
        </div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input id="submit" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>


<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/messages_zh.js"></script> 
<script type="text/javascript" src="/static/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="/static/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="/static/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="/static/js/upload.js"></script>
<script type="text/javascript">
var smallid = [];
var scid = [];
// function funSelect(obj) {
// 	$.getJSON("{:url('subCates')}",{f_id:$("#cates").val()},function(json){
// 		$("#subcates").remove();
// 		console.log(json)
// 		if(json.code==200){
// 			var objelement = '<select  name="subcates" id="subcates" class="select">';
// 			for (var i = 0; i < json.data.length; i++) {
// 				objelement = objelement+'<option value="'+json.data[i].id
// 				+'">&nbsp;'+json.data[i].catename
// 				+'&nbsp;</option>'
// 			}
// 			objelement = objelement+'</select>';
// 			$(".subcates-box").append(objelement);
// 		}
// 	});
// }
var namenum = 0;
var lv2HTML = '<div class="chongzhi smname" id="namenum_'+namenum+'">' +
                '<div class="ygminp">规格</div>'+
                '<input type="text" name="lv2" placeholder="参数名称" class="smallshu ygminp">' +
                '<button class="man shanchu remove_lv2" type="button"><span class="fa fa-times"></span></button>' +
              '</div>';
var formDatas = new FormData();
var formData = new FormData();
var fileall = [];
var imgpz;
var delarrs=[];
$(function(){
	$('#drop_area div img').attr('src','{$data.img}');
	$('#drop_area div img').attr('onerror',"javascript:this.src='/static/img/upload.png'");
	if($("#drop_area div img").attr('src')=='/static/img/upload.png'){
		imgpz='';
	}else{
		imgpz= $("#drop_area div img").attr('src');
	}
	var ue = UE.getEditor('editor');
	var pid='{$data.id}';
	$.ajax({
		type:"post",
		url: "{:url('goodsInfo')}",
		dataType:"text",
		data:{id:pid},
		success:function(data){
			var data = eval('(' + data + ')');
			if(data.spec.length>0){
		        for (var i = 0; i < data.spec.length; i++) {
		          $("#add_lv1").parents('.control-group').eq(0).append('<div class="control-group lv1 formbox1" id="'+data.spec[i].id+'">' +
		              '<div class="controls col-md-12 chongzhi">' +
		                  '<input type="text" name="lv1" placeholder="规格名称" class="money2 gtype guigenum'+i+'" value="'+data.spec[i].sepc_name+'">' +
		                    '<button class="btn btn-warning man4 add_lv2" type="button">'+
		                    '<span class="fa fa-plus"></span>添加参数</button>' +
		                    '<button class="man shanchu remove_lv1 Hui-iconfont btn btn-danger" type="button"><span class="fa fa-times">&#xe6a6;</span></button>' +                     
		              '</div>' +
		              '<div class="controls col-md-12 lv2s boxbig_'+i+'"></div>' +
		          '</div>');
		          for(var j=0;j<data.spec[i].sepc_val.length;j++){
		            $(".boxbig_"+i).append('<div class="chongzhi smname" id="'+data.spec[i].sepc_val[j].id+'">' +
		            '<span>参数：</span>'+
		              '<input type="text" name="lv2" placeholder="参数名称" class="smallshu ygminp">' +
		              '<button class="man shanchu remove_lv2" type="button"><span class="fa fa-times"></span></button>' +
		            '</div>');
		            $(".boxbig_"+i).children().children(".smallshu").eq(j).val(data.spec[i].sepc_val[j].name);
		          }
		          
		        }
		      

		        var tableHTML = '';
		        tableHTML += '<table class="table table-bordered">';
		        tableHTML += '<thead>';
		        tableHTML += '<tr>';
		        for (var i = 0; i < data.spec.length; i++) {
		            tableHTML += '<th width="50" class="guigebig">' + data.spec[i].sepc_name + '</th>';
		        }
		        tableHTML += '<th><div class="kucun">库存</div>\
		                          <div class="input-group">\
		                          </div></th>';
		        tableHTML += '<th><div class="kucun">现价</div>\
		                          <div class="input-group">\
		                          </div></th>';
		        tableHTML += '</tr>';
		        tableHTML += '</thead>';
		        tableHTML += '<tbody>';
		        
		        for (var p = 0; p < data.combination.length; p++) {

		            tableHTML += '<tr data-row="' + (p+1) + '" class="contr trlen_'+p+'" id="'+data.combination[p].id+'">';                
		            var small = data.combination[p].combination.split(',')
		            for(var r=0;r<small.length;r++){
		              tableHTML += '<td width="50" class="smallzhi'+(r+1)+'" data-rc="' + (p+1) + '_' + (r+1) + '"><input class="disbtn" type="text" value="' + small[r] + '" disabled="disabled"/></td>';
		            }                
		            tableHTML += '<td class="priceinp"><input class="form-control stockinp" type="text" name="stock" value="'+data.combination[p].num+'"/></td>';
		            tableHTML += '<td class="priceinp"><input class="form-control priceinp" type="text" name="saleprice" value="'+data.combination[p].money+'"/></td>';
		            tableHTML += '</tr>';
		        }
		        tableHTML += '</tbody>';
		        tableHTML += '</table>';
		         
		        $('#lv_table_con').show();
		        $('#lv_table').html(tableHTML);
		    }
		}
    })
    $('#add_lv1').on('click', function() {
        var num = $(".formbox1").length;
        $(".guigenum").val(num);
        var last = $('.control-group.lv1:last');
        if(num>=3){
            alert("只能添加三个规格")
        }else if (!last || last.length == 0) {
            $(this).parents('.control-group').eq(0).after('<div class="control-group lv1 formbox1">' +
                '<div class="controls chongzhi">' +
                    '<input type="text" name="lv1" placeholder="规格名称" class="money2 gtype guigenum'+num+'">' +
                        '<button class="btn btn-warning man4 add_lv2" type="button">'+
                        '<span class="fa fa-plus"></span>添加参数</button>' +
                        '<button class="man shanchu remove_lv1 Hui-iconfont btn btn-danger" type="button"><span class="fa fa-times"></span>&#xe6a6;</button>' +                 
                '</div>' +
                '<div class="controls lv2s boxbig_'+num+'"></div>' +
            '</div>');
        }else {
            last.after('<div class="control-group lv1 formbox1">' +
                '<div class="controls chongzhi">' +
                    '<input type="text" name="lv1" placeholder="规格名称" class="money2 gtype guigenum'+num+'">' +
                        '<button class="btn btn-warning man4 add_lv2" type="button">'+
                        '<span class="fa fa-plus"></span>添加参数</button>' +
                        '<button class="man shanchu remove_lv1 Hui-iconfont btn btn-danger" type="button"><span class="fa fa-times"></span>&#xe6a6;</button>' +                     
                '</div>' +
                '<div class="controls lv2s boxbig_'+num+'"></div>' +
            '</div>');
        }
        num++;
    });

    
    $(document).on('click', '.remove_lv1', function() {                     
      var bigidone = $(this).parents('.lv1').attr("id");
      scid.push({"id":bigidone});
      $(this).parents('.lv1').remove();
      shualist();
    });
    $(document).on('click', '.add_lv2', function() {
        $(this).parents('.lv1').find('.lv2s').append('<div class="chongzhi smname" id="namenum_'+namenum+'">' +
                '<span>参数：</span>'+
                '<input type="text" name="lv2" placeholder="参数名称" class="smallshu ygminp">' +
                '<button class="man shanchu remove_lv2" type="button"><span class="fa fa-times"></span></button>' +
            '</div>');
        namenum++;
    });
    $(document).on('click', '.remove_lv2', function() {
        var bigidone = $(this).parents().attr("id")
        smallid.push({"id":bigidone});
      $(this).parent().remove();
      shualist();
    });
    function shualist(){
        var lv1Arr = $('input[name="lv1"]');
        if (!lv1Arr || lv1Arr.length == 0) {
            $('#lv_table_con').hide();
            $('#lv_table').html('');
            return;
        }
        for (var i = 0; i < lv1Arr.length; i++) {
            var lv2Arr = $(lv1Arr[i]).parents('.lv1').find('input[name="lv2"]');
            if (!lv2Arr || lv2Arr.length == 0) {
                // alert('请先删除无参数的规格项！');
                return;
            }
        }
        var tableHTML = '';
        tableHTML += '<table class="table table-bordered">';
        tableHTML += '<thead>';
        tableHTML += '<tr>';
        for (var i = 0; i < lv1Arr.length; i++) {
            tableHTML += '<th width="50" class="guigebig">' + $(lv1Arr[i]).val() + '</th>';
        }
        tableHTML += '<th><div class="kucun">库存</div>\
                          <div class="input-group">\
                          </div></th>';
        tableHTML += '<th><div class="kucun">现价</div>\
                          <div class="input-group">\
                          </div></th>';
        tableHTML += '</tr>';
        tableHTML += '</thead>';
        tableHTML += '<tbody>';
         
        var numsArr = new Array();
        var idxArr = new Array();
        for (var i = 0; i < lv1Arr.length; i++) {
            numsArr.push($(lv1Arr[i]).parents('.lv1').find('input[name="lv2"]').length);
            idxArr[i] = 0;
        }
         
        var len = 1;
        var rowsArr = new Array();
        for (var i = 0; i < numsArr.length; i++) {
            len = len * numsArr[i];
             
            var tmpnum = 1;
            for (var j = numsArr.length - 1; j > i; j--) {
                tmpnum = tmpnum * numsArr[j];
            }
            rowsArr.push(tmpnum);
        }
         
        for (var i = 0; i < len; i++) {
            tableHTML += '<tr data-row="' + (i+1) + '" class="contr trlen_'+i+'">';                 
            var name = '';
            for (var j = 0; j < lv1Arr.length; j++) {
                var n = parseInt(i / rowsArr[j]);
                if (j == 0) {
                } else if (j == lv1Arr.length - 1) {
                    n = idxArr[j];
                    if (idxArr[j] + 1 >= numsArr[j]) {
                        idxArr[j] = 0;
                    } else {
                        idxArr[j]++;
                    }
                } else {
                    var m = parseInt(i / rowsArr[j]);
                    n = m % numsArr[j];
                }
                 
                var text = $(lv1Arr[j]).parents('.lv1').find('input[name="lv2"]').eq(n).val();
                if (j != lv1Arr.length - 1) {
                    name += text + '_';
                } else {
                    name += text;
                }
                    tableHTML += '<td width="50" class="smallzhi'+(j+1)+'" data-rc="' + (i+1) + '_' + (j+1) + '"><input class="disbtn" type="text" value="' + text + '" disabled="disabled"/></td>';
            }
             
            tableHTML += '<td class="priceinp"><input class="form-control stockinp" type="text" name="' + name + 'stock" /></td>';
            tableHTML += '<td class="priceinp"><input class="form-control priceinp" type="text" name="' + name + 'saleprice" /></td>';
            tableHTML += '</tr>';
        }
        tableHTML += '</tbody>';
        tableHTML += '</table>';             
        $('#lv_table_con').show();
        $('#lv_table').html(tableHTML);
    }
    $('#update_table').on('click', function() {
            shualist();
    });
});

$(function() {
    var delParent;
    var defaults = {
        fileType: ["jpg", "png", "bmp", "jpeg"],
        fileSize: 1024 * 1024 * 10
    };
    $(".file").change(function() {
        var idFile = $(this).attr("id");
        var file = document.getElementById(idFile);
        var imgContainer = $(this).parents(".z_photo");
        var fileList = file.files;
        var input = $(this).parent();
        var imgArr = [];
        var numUp = imgContainer.find(".up-section").length;
        var totalNum = numUp + fileList.length;
        if (fileList.length > 9 || totalNum > 9) {
            alert("上传图片数目不可以超过9个，请重新选择");
        } else if (numUp < 9) {
            fileList = validateUp(fileList);
            for (var i = 0; i < fileList.length; i++) {
            	fileall.push(fileList[i]);
                var imgUrl = window.URL.createObjectURL(fileList[i]);
                imgArr.push(imgUrl);
                var $section = $("<section class='up-section fl loading'>");
                imgContainer.prepend($section);
                var $span = $("<span class='up-span'>");
                $span.appendTo($section);
                var $img0 = $("<img class='close-upimg'>").on("click", function(event) {
                    event.preventDefault();
                    event.stopPropagation();
                    $(".works-mask").show();
                    delParent = $(this).parent();
                });
                $img0.attr("src", "/static/img/a7.png").appendTo($section);
                var $img = $("<img class='up-img up-opcity'>");
                $img.attr("src", imgArr[i]);
                $img.appendTo($section);
                var $p = $("<p class='img-name-p'>");
                $p.html(fileList[i].name).appendTo($section);
                var $input = $("<input id='taglocation' name='taglocation' value='' type='hidden'>");
                $input.appendTo($section);
                var $input2 = $("<input id='tags' name='tags' value='' type='hidden'/>");
                $input2.appendTo($section);
            }
        }
        setTimeout(function() {
            $(".up-section").removeClass("loading");
            $(".up-img").removeClass("up-opcity");
        }, 450);
        numUp = imgContainer.find(".up-section").length;
        if (numUp >= 9) {
            $(this).parent().hide();
        }
        $(this).val("");
    });
    $(".z_photo").delegate(".close-upimg", "click", function() {
        $(".works-mask").show();
        delParent = $(this).parent();
    });
    $(".wsdel-ok").click(function() {
        $(".works-mask").hide();
        var numUp = delParent.siblings().length;
        delarrs.push(delParent.find("input").val());
        fileall.splice(numUp-delParent.index()-1,1)
        if (numUp < 10) {
            delParent.parent().find(".z_file").show();
        }
        delParent.remove();
    });
    $(".wsdel-no").click(function() {
        $(".works-mask").hide();
    });
    function validateUp(files) {
        var arrFiles = [];
        for (var i = 0, file; file = files[i]; i++) {
            var newStr = file.name.split("").reverse().join("");
            if (newStr.split(".")[0] != null) {
                var type = newStr.split(".")[0].split("").reverse().join("");
                if (jQuery.inArray(type, defaults.fileType) > -1) {
                    if (file.size >= defaults.fileSize) {
                        alert(file.size);
                        alert('您这个"' + file.name + '"文件大小过大');
                    } else {
                        arrFiles.push(file);
                    }
                } else {
                    alert('您这个"' + file.name + '"上传类型不符合');
                }
            } else {
                alert('您这个"' + file.name + '"没有类型, 无法识别');
            }
        }
        return arrFiles;
    }
})
$("#submit").click(function() {
	layer.load(1, {
	  shade: [0.1,'#fff'] //0.1透明度的白色背景
	});
	var id=$("input[name=id]").val();
	var c_id=$("#cates").val();
	var title=$("input[name=title]").val();
    var recommendation=$("textarea[name=recommendation]").val();
	var sort=$("input[name=sort]").val();
	var detail=UE.getEditor('editor').getContent();
	for(var i = 0;i<fileall.length;i++){
         formDatas.append("imgs[]",fileall[i]);
    }
    var list = [];
	for(var i = 0;i<$(".lv1").length;i++){
	  var color = $(".gtype").eq(i).find($(".gtype")).val();              
	  var obj = {};
	  obj.color = $(".gtype").eq(i).val();
	  obj.coid = $(".lv1").eq(i).attr("id");
	  obj.ggarr=[];
	  for(var k=0;k<$(".boxbig_"+i).children().length;k++){
	      var guigebig = $(".boxbig_"+i).children().children(".smallshu").eq(k).val();
	      var shuju = {};
	      shuju.guigebig = $(".boxbig_"+i).children().children(".smallshu").eq(k).val();
	      shuju.shuid = $(".boxbig_"+i).children(".chongzhi").eq(k).attr("id");
	      obj.ggarr.push(shuju);
	  }
	  
	  list.push(obj);
	}
	var menu = [];         
	for(var j=0;j<$(".contr").length;j++){
	  var val = {};
	  val.id = $(".contr").eq(j).attr("id");
	  val.biao=[];
	  for(var t=0;t<$(".trlen_"+j).children("td").length;t++){
	      var price = {};
	      price.inpval = $(".trlen_"+j).children("td").eq(t).children("input").val();
	      val.biao.push(price)
	  }
	  menu.push(val);
	}
    if(formDatas.get('imgs[]')==null){
    	var eimgs="{$data.imgs}";
		$.ajax({
		    type: 'POST',
		    url: "{:url('product_edit')}",
		    data: {id:id,title:title,recommendation:recommendation,img:imgpz,imgs:eimgs,detail:detail,sort:sort,c_id:c_id,menu:menu,list:list,smallid:smallid,scid:scid},
		    success: function(resdata){
		        if(resdata.code==200){
					layer.msg(resdata.msg,{icon:1,time:1000});
					setTimeout("parent.location.reload()",1000);
		        }else{
					layer.msg(resdata.msg,{icon:2,time:3000});
		        }
		    },
		    error: function(){
				layer.msg('数据保存失败',{icon:2,time:3000});
		    }
		})
	}else{
		$.ajax({
		    type: 'POST',
		    url: "{:url('uploadtmds')}",
			contentType:false,
		    processData: false,
			dataType:"json",
			mimeType:"multipart/form-data",
		    data: formDatas,
		    success: function(result){
		        if(result.code==200){
		        	var eimg;
		        	var eimgs;
	        		var testimg="{$data.imgs}";
	        		var testimgarr=testimg.split(",");
	        		for (var i = 0 ; i < testimgarr.length; i++) {
	        			for (var j = 0; j < delarrs.length; j++) {
		        			if(i==delarrs[j]-1){
		        				testimgarr[i]='';
		        			}
	        			}
	        		}
	        		for (var k = 0; k < testimgarr.length; k++) {
	        			if(testimgarr[k]==''){
	        				testimgarr.splice(k,1);
	        				k = k - 1;
	        			}
	        		}
		        	if(result.imgs){
		        		eimg=result.imgs;
	        			eimgs=testimgarr.join()+','+eimg;
		        	}else{
	        			eimgs=testimgarr.join();
		        	}
					$.ajax({
					    type: 'POST',
					    url: "{:url('product_edit')}",
					    data: {id:id,title:title,recommendation:recommendation,img:imgpz,imgs:eimgs,detail:detail,sort:sort,c_id:c_id,menu:menu,list:list,smallid:smallid,scid:scid},
					    success: function(resdata){
							console.log(resdata)
					        if(resdata.code==200){
								layer.msg(resdata.msg,{icon:1,time:1000});
								setTimeout("parent.location.reload()",1000);
					        }else{
								layer.msg(resdata.msg,{icon:2,time:3000});
					        }
					    },
					    error: function(){
							layer.msg('数据保存失败',{icon:2,time:3000});
					    }
					})
		        }else{
					layer.msg('图片上传失败',{icon:2,time:3000});
		        }
		    },
		    error: function(){
				layer.msg('图片上传失败！',{icon:2,time:3000});
		    }
		})
	}
})
var dragImgUpload = new DragImgUpload("#drop_area",{
    callback:function (files) {
        //回调函数，可以传递给后台等等
        if(files[0].size<3145728){
	        var file = files[0];
	        formData.append("file",file);
	        $.ajax({
	              type: 'POST',
	              url: "{:url('uploadtmds')}",
	              data:formData,
	              contentType: false, /*不可缺*/
	              processData: false, /*不可缺*/
	              success: function(response){
	                if(response.code==200){
	                  imgpz=response.photo
	                }else{
	                  alert(response.msg);
	                }
	              },
	              error: function(err){

	              }
	        })
        }else{
        	alert('出错');
        	location.replace(location.href);
        }
    }
});
</script> 
{/block}